package torres.item;

import torres.entity.Entity;
import torres.fileIO.BasicContainer;
import torres.fileIO.ClassContainer;

/**
 * @author Torres
 * Special types of items that can be wielded by Entities to boost stats and attack.
 */
public class Weapon extends EquippableItem {
	
	private WeaponType type;
	
	/**
	 * Creates a new Weapon with given attributes.
	 * @param name Name of weapon
	 * @param id ID of weapon
	 * @param offMod OffensiveMod of weapon
	 * @param armMod DefensiveMod of weapon
	 * @param eType slot(s) occupied by weapon
	 * @param wType type of weapon
	 * @param itemCost Value of TakeableItem
	 */
	public Weapon(String name, int id, int offMod, int armMod, EquipType eType, WeaponType wType, int itemCost) {
		super(name, id, offMod, armMod, eType, itemCost);
		this.setWeaponType(wType);
	}
	
	/**
	 * Creates a new duplicate Weapon.
	 * @param w Weapon to be duplicated
	 */
	public Weapon(Weapon w) {
		this(w.getName(), w.getID(), w.getOffensiveMod(), w.getArmorMod(), w.getType(), w.getWeaponType(), w.getItemCost());
	}
	
	/* (non-Javadoc)
	 * @see torres.item.EquippableItem#use(torres.entity.Entity)
	 */
	public void use(Entity e) {
		e.equipWeapon(this);
	}

	/**
	 * Return weapon's type.
	 * @return Type of weapon
	 */
	public WeaponType getWeaponType() {
		return this.type;
	}
	
	/**
	 * Sets weapon's type
	 * @param type new value of weapon type to be set
	 */
	private void setWeaponType(WeaponType type) {
		this.type = type;
	}
	
	public boolean addToEquipInventory(EquippedInventory equipInventory) {
		return equipInventory.addWeapon(this);
	}
	
	public void removeFromEquipInventory(EquippedInventory equipInventory) {
		equipInventory.removeWeapon(this);
	}
	
	@Override
	public ClassContainer save() {
		ClassContainer curClass = super.save();
		curClass.addProperty(new BasicContainer("type", "Weapon"));
		return curClass;
	}
	
	@Override
	public void load(ClassContainer classContainer) {
		super.load(classContainer);	
	}
}
